//
//  HHAnimationSample.swift
//  HHSwiftuiPractice
//
//  Created by HongMac on 2023/10/5.
//

import SwiftUI

struct HHAnimationSample: View {
    
    @State var isAnimated: Bool = false
    
    var body: some View {
        
        VStack {
            Button {
                withAnimation {
                    isAnimated.toggle()
                }
    
            } label: {
                Text("开始动画")
                    .font(.title2)
                    .foregroundColor(.white)
                    .padding()
                    .background {
                        Color.orange
                    }
                    .cornerRadius(15)
                
            }.padding()

            Spacer()
            
            RoundedRectangle(cornerRadius: isAnimated ? 50 : 25)
                .fill(isAnimated ? Color.yellow : Color.mint)
                .frame(width: isAnimated ? 100 : 200, height: isAnimated ? 100 : 200  , alignment: .center)
//                .rotationEffect(Angle(degrees: isAnimated ? 360 : 0))
                .offset(y:isAnimated ? 300 : 0)
                .rotation3DEffect(Angle(degrees: isAnimated ? 360 : 0), axis: (x: 0.0, y: 0.0, z: 1.0))
            
            Spacer()
            
        }
    }
}

struct HHAnimationSample_Previews: PreviewProvider {
    static var previews: some View {
        HHAnimationSample()
    }
}
